package com.bcr.apachService;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ApachService {

	//启动服务器
	public static void serviceStart(int port){
		
		try {
			//监听端口
			ServerSocket serverSecket = new ServerSocket(port);
			
			//等待连接
			while(true){
				//获得socket
				Socket socket = serverSecket.accept();
				//启动处理线程
				new Processor(socket).start();
				
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {

		//设置默认端口
		int port = 8081;
		//如果是，命令行传过来的端口参数
		if(args.length==1){
			port = Integer.valueOf(args[0]);
		}
		//启动服务器
		new ApachService().serviceStart(port);

	}

}
